<?php
/**
 * User: PunkVv <punkvv@qq.com>
 * Date: 2016/7/7
 * Time: 18:08
 */
//注册插件根命名空间
\think\Loader::addNamespace('addons','../addons/');

/**
 *获取wechat的配置
 */
function get_wechat_option()
{
    $cacheOption = \think\Cache::get('wechat_option');
    if (!$cacheOption) {
        $config = new \app\common\model\Config();
        $data = $config->getValues('1,2,3');

        //公众号配置
        $cacheOption = [
            'debug' => true,
            'app_id' => $data['app_id'],
            'secret' => $data['secret'],
            'token' => $data['token'],
            'log' => [
                'level' => 'debug',
                'file' => '/tmp/easywechat.log',
            ],
            // ...
        ];

        \think\Cache::set('wechat_option', $cacheOption);
    }

    return $cacheOption;
}

/**
 * 处理插件钩子
 * @param $hook
 * @param array $params
 */
function hook($hook, $params = array())
{
    \think\Hook::listen($hook, $params);
}

/**
 * 获取插件类的类名
 * @param $name
 * @return string
 */
function get_addon_class($name)
{
    $class = "addons\\{$name}\\{$name}Addon";
    return $class;
}